package com.opennetexam.manager.sqlprovider;

import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 奶茶
 * Created on 2017/11/14.
 */
public class ExamScenesProvider {

    private static final Logger logger = Logger.getLogger(ExamScenesProvider.class);


    public String findExamScenesListBySomeWhere(Map<String,Object> parameter){
        StringBuilder sb = new StringBuilder();
        String appId = (String) parameter.get("appId");
        String planId = (String) parameter.get("planId");
        String roomId = (String) parameter.get("roomId");
        String subjectId = (String) parameter.get("subjectId");

        sb.append("SELECT x.* FROM ExamScenes AS x join ExamineeArrange AS y ON y.AppID=x.AppID AND y.ExamPlanInfoID=x.ExamPlanInfoID AND y.ExamSceneID=x.ExamSceneID WHERE 1=1");
        if(appId != null && !("").equals(appId)){
            sb.append(" AND y.AppID = \'").append(appId).append("\'");
        }
        if(planId != null){
            sb.append(" AND y.ExamPlanInfoID = \'").append(planId).append("\' ");
        }
        if(roomId != null){
            sb.append(" AND y.ExamRoomID = \'").append(roomId).append("\' ");
        }
        if(subjectId != null){
            sb.append(" AND y.ExamSubjectID = \'").append(subjectId).append("\' ");
        }
        sb.append(" GROUP BY x.AppID,x.ExamPlanInfoID,x.ExamSceneID");

        String sql = sb.toString();
        logger.info(sql);
        return sql;
    }

    public static void main(String[] args){
        Map<String,Object> map = new HashMap<>();
        map.put("appId","1");
        map.put("planId",66);
        map.put("roomId",21);
        map.put("subjectId",246);

//        findExamScenesListBySomeWhere(map);
    }
}
